<?php
    require_once('config.php');
    
    if(!($cache->isFile(CACHE_SQL_NEWS))) {
        $sql = 'SELECT a.*, u.login  FROM ' . ARTICLES_TABLE . ' a, ' . USER_TABLE . ' u WHERE u.id = a.user_id ORDER BY id DESC';
        $query = $pdo->query($sql);
        $newsData = Array();

include('includes/bbcode.class.php');
$bbcode = new bbcode;

        foreach($query as $row) {
            $row['date'] = $date->prepareDate($row['date'], true);
            if(strlen($row['text']) > $site_config['news_scrout']) {
                echo $site_config['news_scrout'];
                $row['text'] = substr($row['text'], 0, $site_config['news_scrout']);
                $row['more'] = true;
            }
            $row['text'] = $bbcode->parse(filterData($row['text'], 'string'));
            $row['title'] = filterData($row['title'], 'string');
            $row['link'] = getNiceUrl($row['title']);
            $row['link'] = $row['id'].'-'.$row['link'];
            $newsData[] = $row;
        }
        $cache->saveFile(CACHE_SQL_NEWS, $newsData);
    } else {
        $newsData = $cache->get(CACHE_SQL_NEWS);
    }
    $tpl->assign('newsData', $newsData);
    
    //Wyświetlenie szablonu
    $tpl->display('index_body.tpl');
?>